﻿using System.Data;
using System.Linq;
using CH.FourBoards.LagerWalti.Service.MasterData;
using CH.FourBoards.LagerWalti.WebFrontEnd.View.Generic.RecordSetView;

namespace CH.FourBoards.LagerWalti.WebFrontEnd.View
{
    public class CategoryList : RecordSetBase
    {

        protected override DataTable CreateRecordSetSource()
        {
            // prepare table
            var table = new DataTable();
            table.Columns.Add("RecordUrl");
            table.Columns.Add("Id");
            table.Columns.Add("Parent");
            table.Columns.Add("Image");
            table.Columns.Add("Name");
            table.Columns.Add("ProductCount");

            // load  data
            var service = new MasterDataService();
            var categories = service.ListCategories().ToList();

            // iterate transactions
            foreach (var category in categories) {

                // add data to row
                var row = table.NewRow();
                row["RecordUrl"] = "#"; // ApplicationRoot + new ExecutionView().CreateExecutionLink(execution.ID);
                row["Id"] = category.Id;
                row["Parent"] = category.ParentCategory == null ? string.Empty : category.ParentCategory.Name;
                row["Image"] = category.Image;
                row["Name"] = category.Name;
                row["ProductCount"] = 0; //category.Products.Count;

                table.Rows.Add(row);
            }

            return table;
        }

    }
}